package unit6.part2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;

public class CollectionTest {
    public static void main(String[] args) {
        Collection<Integer> collection = new LinkedList<>();
        collection.add(1);
        collection.add(2);
        collection.add(9);// 添加
        System.out.println(collection);

        collection.remove(9);// 删除
        System.out.println(collection);

        System.out.println(collection.size());// 大小

        System.out.println(collection.isEmpty());// 是否有元素

        System.out.println(collection.contains(1));// 是否包含指定元素

        Collection<Integer> c2 = new ArrayList<>(collection);// 复制一个集合
        System.out.println(c2);

        c2.addAll(Arrays.asList(3, 4));// 批量添加
        System.out.println(c2);

        c2.removeAll(Arrays.asList(2, 3));// 批量删除
        System.out.println(c2);
    }
}
